<template>
<div class="Ctyllist"  ref="wrapper">
  <div>
    <div class="list">
      <div class="list-header">当前城市</div>
      <p class="class-p">{{this.$store.state.city}}</P>
    </div>
    <div class="list">
      <div class="list-header">热门城市</div>
      <div class="value">
        <div class="class-p" @click="cityclick(item.name)" v-for="item of hot" :key="item.id"><div>{{item.name}}</div></div>
      </div>
    </div>
    <div class="list" v-for="(item,key) of city" :key="key" :ref="key">
      <div class="list-header">{{key}}</div>
      <div>
        <div class="class-p" v-for="innerItem of item" :key="innerItem.id" @click="cityclick(innerItem.name)">{{innerItem.name}}</div>
      </div>
    </div>
  </div>
</div>
</template>

<script>
import Bscroll from 'better-scroll'
export default {
  name: 'Ctyllist',
  mounted () {
    this.scroll = new Bscroll(this.$refs.wrapper, {mouseWheel: true, click: true, tap: true})
  },
  methods: {
    cityclick (city) {
      this.$store.dispatch('changecity', city)
      this.$router.push('/')
    }
  },
  props: {
    hot: Array,
    city: Object,
    letter: String
  },
  watch: {
    letter () {
      if (this.letter) {
        const element = this.$refs[this.letter][0]
        this.scroll.scrollToElement(element)
      }
    }
  }
}
</script>

<style lang="stylus" scoped>
.Ctyllist
  background: #fff
  overflow: hidden
  position: absolute
  left: 0
  right: 0
  bottom: 0
  top: 4.6rem
  .list
    overflow: hidden
    .list-header
      height: 2rem
      line-height: 2rem
      background: #eee
      color: #666
      padding: 0 0 0 1.1rem
    .class-p
        width: 27%
        border: 1px solid #eee
        float: left
        margin: .3rem .35rem
        height: 1.4rem
        line-height: 1.4rem
        text-align: center
    .value
      width: 100%
</style>
